package org.jeecg.modules.online.cgform.utils;

import com.alibaba.fastjson.JSONObject;
import java.math.BigDecimal;
import java.util.Map;
import org.jeecg.common.exception.TuringBootException;
import org.jeecg.modules.online.cgform.entity.OnlCgformField;

/* renamed from: org.jeecg.modules.online.cgform.d.i */
/* loaded from: hibernate-re-3.7.1-RC.jar:org/jeecg/modules/online/cgform/d/i.class */
public class OnlineDbHandler {

    /* renamed from: a */
    public static final String f328a = "int";

    /* renamed from: b */
    public static final String f329b = "Integer";

    /* renamed from: c */
    public static final String f330c = "string";

    /* renamed from: d */
    public static final String f331d = "double";

    /* renamed from: e */
    public static final String f332e = "BigDecimal";

    /* renamed from: f */
    public static final String f333f = "Blob";

    /* renamed from: g */
    public static final String f334g = "Date";

    /* renamed from: h */
    public static final String f335h = "datetime";

    /* renamed from: i */
    public static final String f336i = "Timestamp";

    /* renamed from: j */
    public static final String f337j = "Long";

    /* renamed from: a */
    public static boolean m286a(String str) {
        return "int".equals(str) || "double".equals(str) || "BigDecimal".equals(str) || "Integer".equals(str) || "Long".equals(str);
    }

    /* renamed from: b */
    public static boolean m283b(String str) {
        return "Date".equalsIgnoreCase(str) || "datetime".equalsIgnoreCase(str) || f336i.equalsIgnoreCase(str);
    }

    /* renamed from: a */
    public static String m285a(String str, OnlCgformField onlCgformField, JSONObject jSONObject, Map<String, Object> map) {
        String dbType = onlCgformField.getDbType();
        String dbFieldName = onlCgformField.getDbFieldName();
        String fieldShowType = onlCgformField.getFieldShowType();
        if (jSONObject.get(dbFieldName) == null) {
            return "null";
        }
        m284a(onlCgformField, jSONObject);
        if ("int".equals(dbType)) {
            map.put(dbFieldName, Double.valueOf(Math.floor(Double.parseDouble(jSONObject.getString(dbFieldName)))));
            return "#{" + dbFieldName + ",jdbcType=INTEGER}";
        } else if ("double".equals(dbType)) {
            map.put(dbFieldName, Double.valueOf(jSONObject.getDoubleValue(dbFieldName)));
            return "#{" + dbFieldName + ",jdbcType=DOUBLE}";
        } else if ("BigDecimal".equals(dbType)) {
            map.put(dbFieldName, new BigDecimal(jSONObject.getString(dbFieldName)));
            return "#{" + dbFieldName + ",jdbcType=DECIMAL}";
        } else if ("Blob".equals(dbType)) {
            map.put(dbFieldName, jSONObject.getString(dbFieldName) != null ? jSONObject.getString(dbFieldName).getBytes() : null);
            return "#{" + dbFieldName + ",jdbcType=BLOB}";
        } else if ("Date".equals(dbType) || "datetime".equalsIgnoreCase(dbType)) {
            String string = jSONObject.getString(dbFieldName);
            if ("ORACLE".equals(str)) {
                if ("date".equals(fieldShowType)) {
                    map.put(dbFieldName, string.length() > 10 ? string.substring(0, 10) : string);
                    return "to_date(#{" + dbFieldName + "},'yyyy-MM-dd')";
                }
                map.put(dbFieldName, string.length() == 10 ? jSONObject.getString(dbFieldName) + " 00:00:00" : string);
                return "to_date(#{" + dbFieldName + "},'yyyy-MM-dd HH24:mi:ss')";
            } else if ("POSTGRESQL".equals(str)) {
                if ("date".equals(fieldShowType)) {
                    map.put(dbFieldName, string.length() > 10 ? string.substring(0, 10) : string);
                    return "CAST(#{" + dbFieldName + "} as DATE)";
                }
                map.put(dbFieldName, string.length() == 10 ? jSONObject.getString(dbFieldName) + " 00:00:00" : string);
                return "CAST(#{" + dbFieldName + "} as TIMESTAMP)";
            } else {
                map.put(dbFieldName, jSONObject.getString(dbFieldName));
                return "#{" + dbFieldName + "}";
            }
        } else {
            map.put(dbFieldName, jSONObject.getString(dbFieldName));
            return "#{" + dbFieldName + ",jdbcType=VARCHAR}";
        }
    }

    /* renamed from: a */
    private static void m284a(OnlCgformField onlCgformField, JSONObject jSONObject) {
        String lowerCase = onlCgformField.getDbType().toLowerCase();
        String dbFieldName = onlCgformField.getDbFieldName();
        String dbFieldTxt = onlCgformField.getDbFieldTxt();
        Integer dbLength = onlCgformField.getDbLength();
        Integer dbPointLength = onlCgformField.getDbPointLength();
        if (jSONObject.get(dbFieldName) == null) {
            return;
        }
        boolean z = false;
        if (lowerCase.equalsIgnoreCase("double") || lowerCase.equalsIgnoreCase("BigDecimal")) {
            String[] split = jSONObject.getBigDecimal(dbFieldName).toPlainString().split("\\.");
            z = split[0].length() > dbLength.intValue() - dbPointLength.intValue() || (split.length > 1 ? split[1].length() : 0) > dbPointLength.intValue();
        } else if (lowerCase.equalsIgnoreCase("string")) {
            z = String.valueOf(jSONObject.get(dbFieldName)).length() > dbLength.intValue();
        } else if (lowerCase.equalsIgnoreCase("Integer") || lowerCase.equalsIgnoreCase("int")) {
            z = String.valueOf(jSONObject.get(dbFieldName)).length() > dbLength.intValue();
        }
        if (z) {
            throw new TuringBootException(String.format("%s的长度超出最大长度。", dbFieldTxt));
        }
    }
}
